package org.twndmv.blimpl;

import java.util.List;

import org.twndmv.bl.DriverMgmt;
import org.twndmv.bo.Person;
import org.twndmv.bo.Residence;
import org.twndmv.dao.PersonDAO;
import org.twndmv.jpa.PersonDAOImpl;

public class DriverMgmtImpl implements DriverMgmt {

	private PersonDAO personDAO;
	
	public DriverMgmtImpl() {
		personDAO = new PersonDAOImpl();
	}
	
	public DriverMgmtImpl(PersonDAO personDAO2) {
        this.personDAO = personDAO2;
	}

	public void addDriver(Person newPerson) {
		personDAO.createPerson(newPerson);
	}

	public void moveResidence(long personId, Residence newResidence) {
		Person person = personDAO.getPersonByID(personId);
		person.getResidences().add(newResidence);
		if(newResidence.getMoveOut() == null) {
			person.setCurrentResidence(newResidence);
		}
		personDAO.updatePerson(person);
	}

	public Person getDriver(long id) {
		return personDAO.getPersonByID(id);
	}

	public List<Person> getDriversByLastName(String name) {
		return personDAO.getPersonByLastName(name);
	}

	@Override
	public List<Person> getAllDrivers() {
		return personDAO.getAllDrivers();
	}

}
